<?
/**
 * VoiceOne Voicemail
 *
 * Frontend to ???
 * @package voiceone
 * @subpackage  voicemail
 * @todo Needs documentation and implementation
 */
  include ("../admin/config/cfg.php");
  global $cwBasePath,$cwlang;

//----------------------------------- GET --------------------------------------
  if(count($_GET)==2){
      // Transfer voicemail message from asterisk's folder to wb's folder
      $ret=$asterisk->checkVoiceMailMessage($cwUserInfo[exten],$_GET["filename"]);
      //echo $_GET["filename"]." ret:".$ret;
      if($ret==1){
        // Define relative path (path next to /voiceone_webservices/sandbox)
        $filepath="/voicemail/".$cwUserInfo[exten]."/".$_GET["filename"];
        // if web service is active the file_content is ready to use
        if($soapWrapper===false){
          $file_content=$asterisk->getFileFromSandbox($filepath);
        }
        // if web service is emulated the file_content have to be decoded
        else{
          $file_content=$asterisk->getFileFromSandbox($filepath);
          $file_content=base64_decode($file_content);
        }
        if($file_content!=""){
          $desc=$_GET["desc"].".wav";
          session_start();
          header('Content-Type: '.'audio/wav');
          header('Content-Disposition: attachment; filename="'.$desc.'"');
          //header('Content-Disposition: inline; filename="'.$desc.'"');
          header('Last-Modified: '.gmdate('D, d M Y H:i:s',$stat[9]).' GMT');
          echo $file_content;
          exit();
        } else {
          $alert="<div class=\"AlertBad\">".T_("Unable to play message: server memory exhausted")."</div>";
          goToMainPage($alert,"./");
        }
     } else {
      $alert="<div class=\"AlertBad\">".T_("Unable to play message: server memory exhausted")."</div>";
      goToMainPage($alert,"./");
     }
  }
?>
